package simulation;

public class ScheduleProgram {
	public static boolean[] access;
	public static boolean[] finished;
	public static int size = 0;

	public static synchronized void activateAll() {
		for (int i = 0; i < access.length; i++) {
			finished[i] = false;
			access[i] = false;
		}
	}

	public static synchronized Boolean getAccess(int i) {
		if (i < size)
			return access[i];
		else {
			System.out.println("Invalid access");
			return null;
		}
	}

	public static void initAccess(int i) {
		access = new boolean[i];
		finished = new boolean[i];
		activateAll();
		size = i;
	}

	public static synchronized Boolean masterAcess() {
		boolean result = true;
		for (int i = 0; i < access.length; i++)
			result = result & access[i];
		return result;
	}

	public static synchronized Boolean masterFinish() {
		boolean result = true;
		for (int i = 0; i < finished.length; i++)
			result = result & finished[i];
		return result;
	}

	public static synchronized void setAccess(int i, boolean type) {
		if (i < size)
			access[i] = type;
		else {
			System.out.println("Invalid access");
		}
	}

	public static synchronized void setFinished(int i, boolean type) {
		if (i < size)
			finished[i] = type;
		else {
			System.out.println("Invalid access");
		}
	}

}
